package com.hkpickup.demo.config;

import java.io.*;
import java.util.Properties;

import javax.servlet.ServletContext;

/*
 *  Try to read config from static file.
 *  @reference http://stackoverflow.com/questions/1362545/how-to-load-properties-file-in-google-app-engine
 */
public class ReadProperty {
	public Properties properties; 
	public Properties properties2;
	public ReadProperty() throws FileNotFoundException, IOException{
		
		// Get config file 1
		properties = new Properties(); 
		InputStream is = this.getClass().getClassLoader().getResourceAsStream("My.properties");
		properties.load(is);
		is.close();
		// Get config file 2 where inside package
		properties2 = new Properties(); 
		is = this.getClass().getClassLoader().getResourceAsStream("com/hkpickup/demo/config/My.properties");
		properties2.load(is);
		is.close();
	}
	
	/**
	 * @param args
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException, IOException {
		ReadProperty prop = new ReadProperty();
		System.out.printf("user: %s\n", prop.properties.getProperty("user", "none"));
		System.out.printf("user: %s\n", prop.properties2.getProperty("user", "none"));
	}

}
